﻿using System;
using System.Web.UI.WebControls;
using System.Data;
using ART.Common;

namespace ART.Admini.Setting
{
    public partial class PermissList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }
        protected void BindList()
        {

            #region __________Where语句__________

            string SqlWhere = "  1=1";


            #endregion
            Rep_List.ShowPagenation = false;
            Rep_List.PageLink = "PermissList.aspx";
            Rep_List.PageSize = 200;
            Rep_List.CurrentPage = LYRequest.GetInt("page", 1);

            DataSet ds = BLL.GetListByPage.GetDataSet_NoCache("permissions", "*", SqlWhere, "", "Sort desc,id asc", "ID", Rep_List.CurrentPage, Rep_List.PageSize, 1);

            //Rep_List.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            DataTable dt1 = JTree.GetTreeTable(ds.Tables[1], "ParentID", "PermissName");
            JBind.BindList(Rep_List, dt1);
        }
        protected string GetName(object name,object parentid)
        {
            if (parentid.ToString() == "0")
            {
                return "<span style='Color:#ff0000'>├ " + name + "</span>";
            }
            else
            {
                return GetLenSpace(Utils.StrToInt(parentid, 0)) + "├ " + name;
            }
        }
        private string GetLenSpace(int parentid)
        {
            string tmp = "　";
            if (parentid!=0)
            {
                tmp += GetLenSpace(new BLL.B_permissions().GetModel(parentid).ParentId);
            }
            return tmp;
        }

        protected void Btn_Del_Click(object sender, EventArgs e)
        {
            string GetID = ((LinkButton)sender).CommandArgument;
#warning xxxx
            if (!BLL.B_TBAdmin.IsPermissions(7))
            {
                MessageBox.Alert(sender, "没有删除权限!");
                return;
            }

            if (new BLL.B_permissions().Delete(int.Parse(GetID)))
            {
                MessageBox.AlertToUrl(sender, "删除成功", Request.Url.ToString());
            }
            else
            {
                MessageBox.AlertToUrl(sender, "删除失败", Request.Url.ToString());
            }
        }

    }
}
